const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ESLintPlugin = require('eslint-webpack-plugin')

module.exports = {
   entry: './src/index.ts',
   output: {
      path: path.resolve(__dirname, 'dist'),
      filename: 'app.js',
   },
   module: {
      rules: [
         {
            test: /\.ts$/,
            use: 'ts-loader',
         },
         {
            test: /\.css$/i,
            use: ['style-loader', 'css-loader'],
         },
         {
            test: /\.m?js$/,
            // 排除指定目录里的 js （不进行编译降级）
            exclude: /(node_modules|bower_components)/,
            use: {
               loader: 'babel-loader',
               options: {
                  presets: ['@babel/preset-env'], // 预设规则
               },
            },
         },
      ],
   },
   plugins: [
      new HtmlWebpackPlugin({
         template: './public/index.html',
      }),
      new ESLintPlugin({
         fix: true,
         extensions: ['js', 'jsx', 'ts', 'tsx'],
         exclude: 'node_modules',
      }),
   ],
   resolve: {
      extensions: ['.ts', '.js'],
   },
   mode: 'development',
   devServer: {
      static: {
         directory: path.join(__dirname, '/'),
      },
   },
}
